//
//  SDCustomActivity.m
//  SBooks
//
//  Created by shansander on 2016/11/30.
//  Copyright © 2016年 shansander. All rights reserved.
//

#import "SDCustomActivity.h"

NSString * const UIActivityTypeSDCustomMine = @"SDCustomMine";

@implementation SDCustomActivity
{
    NSArray * activityUrls;
}

-(NSString *)activityType
{
    return UIActivityTypeSDCustomMine;
}
- (NSString *)activityTitle
{
    return @"保存图片";
}
- (UIImage *)activityImage
{
    return [UIImage imageNamed:@"saveimage"];
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
//    指定可以处理的数据类型，如果可以处理则返回YES
    return YES;
}
- (void)prepareWithActivityItems:(NSArray *)activityItems
{
    //预备事情
    activityUrls = activityItems;
    NSLog(@"%@",activityItems);
    
}

+ (UIActivityCategory)activityCategory
{
    return UIActivityCategoryAction;
}

- (void)performActivity
{
    NSLog(@"%s",__func__);
    for (NSURL * url in activityUrls) {
        UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
        NSLog(@"%@",image);
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    }
    
}

@end
